package com.ccjq.yaoqing.service.impl;

import com.ccjq.yaoqing.dao.StudentDao;
import com.ccjq.yaoqing.dao.impl.StudentDaoImpl;
import com.ccjq.yaoqing.domain.Address;
import com.ccjq.yaoqing.domain.Student;
import com.ccjq.yaoqing.service.StudentService;
import com.ccjq.yaoqing.util.UuidUtils;

import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

/**
 * describe:
 *
 * @author xugang
 * @date 2018/12/6 17:30
 */
public class StudentServiceImpl implements StudentService {

    private StudentDao dao;

    public StudentServiceImpl() {
        dao = new StudentDaoImpl();
    }

    @Override
    public int save(Student student) {
        String userId = UuidUtils.generateShortUUID("SN-", 17);
        String showTime = "";
        SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateTimeInstance();
        format.applyPattern("yyyy-MM-dd HH:mm:ss");
        showTime = format.format(new java.util.Date(System.currentTimeMillis()));
        int result = dao.save(userId, student.getName(), student.getSchool(), student.getPhone(), new Date(System.currentTimeMillis()),showTime);
        return result;
    }

    @Override
    public Address getTimeAndAddress() {
        return dao.getTimeAndAddress();
    }
}
